Merging of sorted lists using array pair

ABSTRACT

The formulation of a merged sorted list from multiple input sorted lists in multiple phases using an array pair. Initially, the first array is contiguously populated with the input sorted lists. In the first phase, the first and second input sorted lists are merged into a first intermediary merged list within the second array. Each subsequent phase merges a prior intermediary merged list resulting from the prior phase and, a next input sorted list in the first array to generate a next intermediary merged list, or a merged sorted list if there or no further input in the first array. The intermediary merged lists alternate between the first array and the second array from one phase to the next phase.

BACKGROUND

A list is a sequence of elements. A sorted list is a list that is sortedaccording to a particular sorting priority (such as alphabetical,increasing value, and so forth). A sorted list guarantees that for everypair of consecutive elements, the previous element satisfies theparticular sorting priority with respect to the subsequent element. Forinstance, suppose that the list includes a sequence of integers, andthat the sorting priority is an increasing value sorting priority. Inthat case, the list of integers would be sorted according to increasingvalue if for every pair of consecutive integer in the sequence, thesubsequent integer is equal to or greater than the previous integer.Each sorted list includes a head element, which is the highest priorityin the sorting priority, and thus the first element in the sorted list.Each sorted list also includes a tail element, which is a lowestpriority in the sorting priority, and thus the last element in thesorted list.

There is a particular method (referred to herein as a “priority queuemethod”) that was developed a number of decades ago to merge inputsorted lists into a merged sorted list that is sorted according to thesame sorting priority as the input sorted lists. This priority queuemethod uses a priority queue in order to formulate a merged list, andinvolves multiple phases of sorting operation. In the first phase, eachof the head elements from all of the input sorted lists are placed inthe priority queue, and thus each space in the priority queuecorresponds to an input sorted list. In each sorting phase, the mergedsorted list is extended by one element by moving the highest priorityelement that is within the priority queue to the end of the mergedsorted list as a new tail element of the merged sorted list. The highestunprocessed priority element from the input sorted list corresponding tothe space vacated by this move is then processed by copying the elementinto vacated space, thus completing a sorting phase.

SUMMARY

In accordance with at least one embodiment described herein, a mergedsorted list is formulated from multiple input sorted lists in multiplephases using an array pair. Initially, the first array is contiguouslypopulated with the input sorted lists. In the first phase, the first andsecond input sorted lists are merged into a first intermediary mergedlist in the second array. Each subsequent phase merges a priorintermediary merged list resulting from the prior phase, a next inputsorted list in the first array to generate a next intermediary mergedlist, or a final merged sorted list if there or no further input in thefirst array. The intermediary merged lists alternate between the firstarray and the second array from one phase to the next phase.

In some embodiments, the merging technique may be particularly efficientfor modern microprocessors that are more efficient at sequential readand write operations, since the merging may be performed in sequentialoperation through the array pair. This Summary is not intended toidentify key features or essential features of the claimed subjectmatter, nor is it intended to be used as an aid in determining the scopeof the claimed subject matter.

BRIEF DESCRIPTION OF THE DRAWINGS

In order to describe the manner in which the above-recited and otheradvantages and features can be obtained, a more particular descriptionof various embodiments will be rendered by reference to the appendeddrawings. Understanding that these drawings depict only sampleembodiments and are not therefore to be considered to be limiting of thescope of the invention, the embodiments will be described and explainedwith additional specificity and detail through the use of theaccompanying drawings in which:

FIG. 1 abstractly illustrates a computing system in which someembodiments described herein may be employed;

FIG. 2 illustrates a flowchart of flowchart of a method for formulatinga merged sorted list in accordance with the principles described herein;

FIG. 3 illustrates a flowchart of a method for processing each sortingphase of the sorting operation of FIG. 2;

FIG. 4A through 4E show five sequential sorting state operationsassociated with a first sorting phase of an example in which a firstinput sorted list and a second input sorted list are combined into afirst intermediate merged sorted list;

FIG. 5A through 5J show ten sequential sorting state operationsassociated with a second sorting phase of the example in which the firstintermediate merged sorted list is merged with a third input sorted listto form a second intermediate (and possibly a final) merged sorted list;

FIG. 6 illustrates a flowchart of a method for accessing input sortedlists; and

FIG. 7 illustrates a flowchart of a more generalized method forprocessing elements to form sorted lists.

DETAILED DESCRIPTION

In accordance with embodiments described herein, the formulation of amerged sorted list is described. The formulation uses multiple inputsorted lists and occurs in multiple phases using an array pair.Initially, the first array is contiguously populated with the inputsorted lists. In the first phase, the first and second input sortedlists are merged into a first intermediary merged list in the secondarray. Each subsequent phase merges a prior intermediary merged listresulting from the prior phase and, a next input sorted list in thefirst array to generate a next intermediary merged list, or a mergedsorted list if there or no further input in the first array. Theintermediary merged lists alternate between the first array and thesecond array from one phase to the next phase.

Some introductory discussion of a computing system will be describedwith respect to FIG. 1. Then, the principles of the merging of sortedlists will be described with respect to FIGS. 2 through 7.

Computing systems are now increasingly taking a wide variety of forms.Computing systems may, for example, be handheld devices, appliances,laptop computers, desktop computers, mainframes, distributed computingsystems, or even devices that have not conventionally been considered acomputing system. In this description and in the claims, the term“computing system” is defined broadly as including any device or system(or combination thereof) that includes at least one physical andtangible processor, and a physical and tangible memory capable of havingthereon computer-executable instructions that may be executed by theprocessor. The memory may take any form and may depend on the nature andform of the computing system. A computing system may be distributed overa network environment and may include multiple constituent computingsystems.

As illustrated in FIG. 1, in its most basic configuration, a computingsystem 100 includes at least one processing unit 102 andcomputer-readable media 104. The computer-readable media 104 mayconceptually be thought of as including physical system memory, whichmay be volatile, non-volatile, or some combination of the two. Thecomputer-readable media 104 also conceptually includes non-volatile massstorage. If the computing system is distributed, the processing, memoryand/or storage capability may be distributed as well.

As used herein, the term “executable module” or “executable component”can refer to software objects, routings, or methods that may be executedon the computing system. The different components, modules, engines, andservices described herein may be implemented as objects or processesthat execute on the computing system (e.g., as separate threads). Suchexecutable modules may be managed code in the case of being executed ina managed environment in which type safety is enforced, and in whichprocesses are allocated their own distinct memory objects. Suchexecutable modules may also be unmanaged code in the case of executablemodules being authored in native code such as C or C++.

In the description that follows, embodiments are described withreference to acts that are performed by one or more computing systems.If such acts are implemented in software, one or more processors of theassociated computing system that performs the act direct the operationof the computing system in response to having executedcomputer-executable instructions. For example, such computer-executableinstructions may be embodied on one or more computer-readable media thatform a computer program product. An example of such an operationinvolves the manipulation of data. The computer-executable instructions(and the manipulated data) may be stored in the memory 104 of thecomputing system 100. Computing system 100 may also containcommunication channels 108 that allow the computing system 100 tocommunicate with other processors over, for example, network 110.

Embodiments described herein may comprise or utilize a special purposeor general-purpose computer including computer hardware, such as, forexample, one or more processors and system memory, as discussed ingreater detail below. Embodiments described herein also include physicaland other computer-readable media for carrying or storingcomputer-executable instructions and/or data structures. Suchcomputer-readable media can be any available media that can be accessedby a general purpose or special purpose computer system.Computer-readable media that store computer-executable instructions arephysical storage media. Computer-readable media that carrycomputer-executable instructions are transmission media. Thus, by way ofexample, and not limitation, embodiments of the invention can compriseat least two distinctly different kinds of computer-readable media:computer storage media and transmission media.

Computer storage media includes RAM, ROM, EEPROM, CD-ROM or otheroptical disk storage, magnetic disk storage or other magnetic storagedevices, or any other tangible storage medium which can be used to storedesired program code means in the form of computer-executableinstructions or data structures and which can be accessed by a generalpurpose or special purpose computer.

A “network” is defined as one or more data links that enable thetransport of electronic data between computer systems and/or modulesand/or other electronic devices. When information is transferred orprovided over a network or another communications connection (eitherhardwired, wireless, or a combination of hardwired or wireless) to acomputer, the computer properly views the connection as a transmissionmedium. Transmissions media can include a network and/or data linkswhich can be used to carry desired program code means in the form ofcomputer-executable instructions or data structures and which can beaccessed by a general purpose or special purpose computer. Combinationsof the above should also be included within the scope ofcomputer-readable media.

Further, upon reaching various computer system components, program codemeans in the form of computer-executable instructions or data structurescan be transferred automatically from transmission media to computerstorage media (or vice versa). For example, computer-executableinstructions or data structures received over a network or data link canbe buffered in RAM within a network interface controller (e.g., a“NIC”), and then eventually transferred to computer system RAM and/or toless volatile computer storage media at a computer system. Thus, itshould be understood that computer storage media can be included incomputer system components that also (or even primarily) utilizetransmission media.

Computer-executable instructions comprise, for example, instructions anddata which, when executed at a processor, cause a general purposecomputer, special purpose computer, or special purpose processing deviceto perform a certain function or group of functions. The computerexecutable instructions may be, for example, binaries, intermediateformat instructions such as assembly language, or even source code.Although the subject matter has been described in language specific tostructural features and/or methodological acts, it is to be understoodthat the subject matter defined in the appended claims is notnecessarily limited to the described features or acts described above.Rather, the described features and acts are disclosed as example formsof implementing the claims.

Those skilled in the art will appreciate that the invention may bepracticed in network computing environments with many types of computersystem configurations, including, personal computers, desktop computers,laptop computers, message processors, hand-held devices, multi-processorsystems, microprocessor-based or programmable consumer electronics,network PCs, minicomputers, mainframe computers, mobile telephones,PDAs, pagers, routers, switches, and the like. The invention may also bepracticed in distributed system environments where local and remotecomputer systems, which are linked (either by hardwired data links,wireless data links, or by a combination of hardwired and wireless datalinks) through a network, both perform tasks. In a distributed systemenvironment, program modules may be located in both local and remotememory storage devices.

FIG. 2 illustrates a flowchart of flowchart of a method 200 forformulating a merged sorted list in accordance with the principlesdescribed herein. The method 200, as well as any other methods describedherein may be performed by a computing system such as the computingsystem 100 of FIG. 1. In particular, if implemented in software, theprocessor(s) 102 execute computer-executable instructions present on acomputer-readable media (such as a computer-readable storage media)constituting all or part of a computer program product.

For input, the method 200 uses multiple input sorted lists (act 201)that are each sorted in accordance with a sorting priority. A particularexample will be used herein to aid in the understanding of theprinciples described herein. In this particular example, there are threeinput sorted lists, each including integer elements, which are sortedfrom lowest to highest. Three sorted lists are as follows:

-   -   Sorted List A: 1, 2, 3, 4, 9    -   Sorted List B: 5, 8    -   Sorted List C: 2, 4, 7

For this example, a correctly merged sorted list would be as follows:

Merged Sorted List: 1, 2, 2, 3, 4, 4, 5, 7, 8, 9

Before describing the merging operating in accordance with theprinciples described herein, a mechanism for merging sorted lists inaccordance with the prior art priority queue method will first bedescribed. Part of the reason for describing this first mechanism willbe to allow the reader to clearly see how much more complex the mergingprocess is in accordance with the principles described herein ascompared to the prior art merging mechanism. Counterintuitively, themore complex merging process in accordance with the principles describedherein is actually more efficiently performed by modern processors thatthe conventional priority queue method.

In the first phase of the priority queue method, a priority queue havingthe same number of elements as there are input sorted lists is firstestablished and populated with the head element from each of the inputsorted list. When an element from the input sorted list is populatedinto the priority queue, the element is removed from the input sortedlist. Thus, at the beginning of the first sorting phase, the state ofoperation is as follows:

Sorted List A: 2, 3, 4, 9

Sorted List B: 8

Sorted List C: 4, 7

Priority Queue: 1, 5, 2

Thus, the first element in the priority queue is populated with anelement from input sorted list A, the second element in the priorityqueue is populated with an element from input sorted list B, and thelast element in the priority queue is populated with an element frominput sorted list C.

In each sorting phase, the highest priority element is removed from thepriority queue and placed at the end of the merged sorted list, and thespace that is vacated is filled with the next element from thecorresponding sorted list. Thus, after the first sorting phase, thesorting state is as follows:

Sorted List A: 3, 4, 9

Sorted List B: 8

Sorted List C: 4, 7

Priority Queue: 2, 5, 2

Merged Sorted List: 1

Note that the integer 1 that was originally in sorted list A has beenremoved from the priority queue as the head element in the merged sortedlist. To replenish the priority queue, the next element (integer 2) inthe sorted list A has been removed from the sorted list A, and placed inthe vacated left spot of the priority queue.

Each sorting phase continues with this same process. Thus, after thenext sorting phase, the sorting state is as follows:

Sorted List A: 4, 9

Sorted List B: 8

Sorted List C: 4, 7

Priority Queue: 3, 5, 2

Merged Sorted List: 1, 2

Note that the integer 2 that was originally in sorted list A has beenremoved from the priority queue as the new tail element in the mergedsorted list. To replenish the priority queue, the next element (integer3) in the sorted list A has been removed from the sorted list A, andplaced in the vacated left spot of the priority queue. There were twointeger elements of value 2 in the priority queue prior to the secondsorting phase. Either integer element of value 2 could have been chosenconsistent with this method.

Continuing, after the third sorting phase, the sorting state is asfollows:

Sorted List A: 4, 9

Sorted List B: 8

Sorted List C: 7

Priority Queue: 3, 5, 4

Merged Sorted List: 1, 2, 2

The integer 2 has been moved from the right spot (corresponding tosorted list C) as the new tail element of the merged sorted list.Furthermore, the next value of the sorted list C (integer 4) has beenmoved to the vacated right spot.

After the fourth sorting phase, the sorting state is as follows:

Sorted List A: 9

Sorted List B: 8

Sorted List C: 7

Priority Queue: 4, 5, 4

Merged Sorted List: 1, 2, 2, 3

The integer 3 has been moved from the left spot (corresponding to sortedlist A) as the new tail element of the merged sorted list. Furthermore,the next value of the sorted list A (integer 4) has been moved to thevacated right spot.

After the fifth sorting phase, the sorting state is as follows:

Sorted List A: *

Sorted List B: 8

Sorted List C: 7

Priority Queue: 9, 5, 4

Merged Sorted List: 1, 2, 2, 3, 4

The integer 4 has been moved from the left spot (corresponding to sortedlist A) as the new tail element of the merged sorted list. Furthermore,the next value of the sorted list A (integer 4) has been moved to thevacated right spot. This leaves the sorted list A empty as representedby the asterisk.

After the sixth sorting phase, the sorting state is as follows:

Sorted List A: *

Sorted List B: 8

Sorted List C: *

Priority Queue: 9, 5, 7

Merged Sorted List: 1, 2, 2, 3, 4, 4

The integer 4 has been moved from the right spot (corresponding tosorted list C) as the new tail element of the merged sorted list.Furthermore, the next value of the sorted list C (integer 7) has beenmoved to the vacated right spot. This leaves the sorted list C alsoempty as represented by the asterisk.

After the seventh sorting phase, the sorting state is as follows:

Sorted List A: *

Sorted List B: *

Sorted List C: *

Priority Queue: 9, 8, 7

Merged Sorted List: 1, 2, 2, 3, 4, 4, 5

The integer 5 has been moved from the center spot (corresponding tosorted list B) as the new tail element of the merged sorted list.Furthermore, the next value of the sorted list B (integer 8) has beenmoved to the vacated right spot. This leaves the sorted list B alsoempty as represented by the asterisk. As all input sorted lists are nowempty, the input sorted lists will not be shown in the remaining of thephases of this method.

After the eighth sorting phase, the sorting state is as follows:

Priority Queue: 9, 8, *

Merged Sorted List: 1, 2, 2, 3, 4, 4, 5, 7

The integer 7 has been moved from the right spot (corresponding tosorted list C) as the new tail element of the merged sorted list. Asthere are no further elements within the sorted list C, the right spotof the priority queue remains empty as represented by the asterisk.

After the ninth sorting phase, the sorting state is as follows:

Priority Queue: 9, *, *

Merged Sorted List: 1, 2, 2, 3, 4, 4, 5, 7, 8

The integer 8 has been moved from the center spot (corresponding tosorted list B) as the new tail element of the merged sorted list. Asthere are no further elements within the sorted list B, the center spotof the priority queue remains empty as represented by the asterisk.

After the tenth sorting phase, the sorting state is as follows:

Priority Queue: *, *, *

Merged Sorted List: 1, 2, 2, 3, 4, 4, 5, 7, 8, 9

The integer 9 has been moved from the center spot (corresponding tosorted list A) as the new tail element of the merged sorted list. Thisleaves the priority queue empty, and also completes the merged sortedlist.

This priority queue method does merge sorted lists, but it is notefficient to perform on a computing system. In accordance with theprinciples described herein, merging of the input sorted list isperformed in a manner that is more efficiently performed by modernprocessors. In particular, the sorting is performed using a pair ofarrays, and using largely sequential read and write operations.Furthermore, the sorting lends itself to more efficient processing bymultiple cores and parallel implementations. For instance, the sortingmay be performed across parallel or different cores, or across multiplemachines.

Returning to method 200 and the particular example, recall that afterthe input sorted lists are accessed (act 201) in the example, thesorting state is as follows:

Sorted List A: 1, 2, 3, 4, 9

Sorted List B: 5, 8

Sorted List C: 2, 4, 7

The input sorted lists are then optionally arranged in order ofincreasing size (act 202). The input sorted lists A through C mightrepresent all of the input sorted lists that are to be merged. However,in one implementation, they might represent just a subset of the inputsorted lists to be merged. Processing the input sorted lists as subsetsmay have an advantage of reducing a number of writes involved with themerging operation.

For instance, consider the case in which there are six sorted lists (a,b, c, d, e and f) that are to be sorted. Suppose that input sorted lista has 5 elements, input sorted list b has 6 elements, and input sortedlists c through f each have 7 elements. In the method described below,merging input sorted lists a and b (to form sorted list ab) wouldinvolve 11 writes, one for each element in the combined sorted list.Merging input sorted list ab and input sorted list c would result in 18writes (as there are 11 elements in input sorted list ab and 7 in inputsorted list c) to generate sorted list abc. Merging input sorted listabc and input sorted list d would result in 25 writes (as there are 18elements in input sorted list abc and 7 in input sorted list d) togenerate sorted list abcd. Merging input sorted list abcd and inputsorted list e would result in 32 writes (as there are 25 elements ininput sorted list abcd and 7 in input sorted list e) to generate sortedlist abcde. Merging input sorted list abcde and input sorted list fwould result in 39 writes (as there are 32 elements in input sorted listabcde and 7 in input sorted list ef) to generate the final merged sortedlist abcdef. Accordingly, using this technique, there would be a totalof 125 writes (11+18+25+32+39).

However, a reduced number of writes might be accomplished by firstpartitioning the input sorted lists into subsets. For instance, supposeagain the input sorted list a is merged with input sorted list b using11 writes the same as above to generate merged sorted list ab. However,input sorted list c might be merged with input sorted list d to generatemerged sorted list cd using 14 writes (since input sorted lists c and deach have 7 elements). Input sorted list e might be merged with inputsorted list f to generate merged sorted list ef also using 14 writes(since input sorted lists e and f each have 7 elements). This wouldallow for some parallelism as merged sorted lists ab, cd, and ef couldbe formed in parallel. Input sorted list ab may then be combined withinput sorted list cd to generate merged list abcd using 25 writes (sinceinput sorted list ab has 11 elements and input sorted list cd has 14elements). Input sorted list abcd may then be merged with input sortedlist ef to generate the final merged list abcdef using 39 writes (sinceinput sorted list abcd has 25 elements and input sorted list ef has 14elements). Accordingly, using this subsetting of the input sorted lists,there would be a total of 103 writes (11+14+14+25+39). Furthermore,subsetting in this way allowed for some parallel processing to occur.

In the example herein, in which input sorted lists A, B and C arediscussed, the input sorted lists could represent the entire set ofinput sorted lists, or could represent just a subset of the input sortedlists. In the latter case, the described technique may then operate onthe output merged sorted list as a new input sorted list using the sametechnique.

In any case, referring only to the input sorted lists A, B and C, sortedlist B is smallest and thus would be arranged first in the sequence. Thesorted list C is the next smallest and thus would be arranged next inthe sequence. The sorted list A is the largest and thus would be thelast in the sequence. Act 202 is an optional optimization that serves toreduce the number of copy operations between the two arrays in the arraypair.

A first array of the pair is then contiguously populated with the inputsorted lists (act 203). The result would be as follows:

First Array: 5, 8, 2, 4, 7, 1, 2, 3, 4, 9

The first array and a second array are then used to merge the multipleinput sorted lists (act 204), which merging occurs in multiple phases.For instance, FIG. 4A illustrates a sorting state at the beginning ofthe first sorting phase in which the sorted lists B, C and A arecontiguously placed within the first array 401. The second array 402 isof the same size as the first array 401, but is empty. For instance, ifthe method 200 is performed by the computing system 100 of FIG. 1, themethod first array 401 and the second array 402 may be located in memoryof the computer-readable media 104.

In the first phase, the first two sorted lists in the first array areformed into a first intermediary merged sorted list located in thesecond array. In the second phase, the first intermediary merged sortedlist is merged with the third sorted list in the first array to form asecond intermediary sorted list in the first array. However, if therewere only two sorted lists to merge, there would be no such secondphase. Note that the location of the current intermediary merged sortedlist alternates between the arrays. Thus, for odd numbered phases, theresulting intermediary merged sorted list is located in one of thearrays, and for even numbered phases, the resulting intermediary mergedsorted list is located in another of the array. More generally stated,each phase after the first phase merges the prior intermediary mergedsorted list resulting from the prior phase into the next input sortedlist to generate the next intermediary merged sorted list (or the finalmerged sorted list if there or no further input sorted lists toprocess).

FIG. 3 illustrates a flowchart of a method 300 for processing eachsorting phase of the sorting operation of act 204 of FIG. 2. A firstinput cursor is established (act 301) at the first element of the firstinput sorted list in the first array (if the first sorting phase) or atthe first element of the prior intermediary merged sorted list (if asubsequent sorting phase). For instance, FIG. 4A illustrates a sortingstate at the beginning of the first phase of sorting in which there is afirst input cursor 411 positioned at the first element of the inputsorted list B, which is the first input sorted list that is contiguouslyplaced in the first array 401. The first array 401 and the second array402 are memory locations.

A second input cursor is established (act 302) at the first element inthe next sorted list in the first array that has not yet been processed.In the case of the first phase, this would be the second input sortedlist in the contiguous sorted lists. In the case of FIG. 4A, in whichthe sequence includes sorted lists B, C and A contiguously positioned inthat order, the cursor 412 is positioned at the first element of theinput sorted list C. For convenience, a third input cursor 413 is alsoshown positioned at the first element of the last input sorted list(sorted list A) in the first array.

An output cursor is established (act 303) at the beginning of the secondarray (if the sort phase is the first sort phase) or at the beginning ofthe opposite array as that which contains the prior intermediary mergedsorted list (if the sort phase is after the first sort phase). Forinstance, in FIG. 4A, output cursor 421 is positioned at the beginningof the empty second array 402.

The method 300 then involves an act of generating a next intermediarymerged sorted list (act 310) by sequentially assigning values to theelements of the next intermediary sorted list. Accordingly, the contentof act 310 may be performed for each element of the next intermediarysorted list. This will be demonstrated referring to the specific examplewith reference to FIGS. 4A through 4E.

The value of the element pointed to by the first input cursor iscompared with the value at the element pointed to by the second inputcursor (decision block 311). For instance, in FIG. 4A, the integer 5pointed to by first input cursor 411 is compared with the integer 2pointed to by the second input cursor 412.

If the value at the element pointed to by the first input cursorsatisfies a sorting priority with respect to the value at the elementpointed to by the second input cursor (“Yes” in decision block 311), thecorresponding element of the next intermediary merged sorted list ispopulated with the value pointed to by the first input cursor (act 321).It is then determined whether or not there are more elements in thefirst sorted list (if this is the first sort phase) or the priorintermediary merged sorted list (if this is a subsequent sort phase)(decision block 322). This decision need not be made expressly withevery iteration of decision block 322. For instance, the check need notbe performed if act 310 has not yet been performed for at least a numberof times that is equal to or less than a minimum length of either of theinput sorted lists. However, even if this check is not expresslyperformed, the check is still implicit by referencing that the number oftimes that act 310 has been performed is still equal to or less thanthis minimum number. If there are not any further elements (“No” indecision block 322), then the remaining values of the opposite sortedlist beginning from the second input cursor is/are populated as the lastvalue of the next intermediary merged sorted list (act 312), and thatsorting phase ends (act 304). If there are further elements (“Yes” indecision block 322), then the first input cursor is moved to the nextneighboring element if the first sorted list (if this is the first sortphase) or the next intermediary merged sorted list (if this is asubsequent sort phase) (act 323). Furthermore, the output cursor ispositioned at the next element in the first sorted list (if this is thefirst sort phase) or the next intermediary merged sorted list (if thisis a subsequent sort phase) (also act 323).

If the value at the element pointed to by the first input cursor doesnot satisfy a sorting priority with respect to the value at the elementpointed to by the second input cursor (“No” in decision block 311), thecorresponding element of the next intermediary merged sorted list ispopulated with the value pointed to by the second input cursor (act331). It is then determined whether or not there are more elements leftin the next input sorted list (decision block 332). If not, theremaining values of the opposite sorted list beginning from the firstinput cursor is/are populated as the last value of the next intermediarymerged sorted list (act 312), and that sorting phase ends (act 304). Ifthere are further elements (“Yes” in decision block 332), then thesecond input cursor is moved to the next neighboring element of the nextsorted list (act 333). Furthermore, the output cursor is positioned atthe next element in the next intermediary merged sorted list (also act333).

For instance, in FIG. 4A, the integer 5 pointed to by the input cursor411 is not equal to or less than the integer 2 pointed to by the inputcursor 412 (“No” in decision block 311). Accordingly, the correspondingelement of the next intermediary merged sorted list (i.e., the elementpointed to by the output cursor 421) is populated with the value 2pointed to by the input cursor 412 (act 331). There are more elementswithin the second sorted list (“Yes” in decision block 332), and thusthe second input cursor 412 and the output cursor 421 are both advanced(act 333). The resulting sorting state 400B is illustrated in FIG. 4B.

In FIG. 4B, the integer 5 pointed to by the input cursor 411 is notequal to or less than the integer 4 pointed to by the input cursor 412(“No” in decision block 311). Accordingly, the corresponding element atthe output cursor 421 is populated with the value 4 pointed to by theinput cursor 412 (act 331). There are more elements within the secondsorted list (“Yes” in decision block 332), and thus the second inputcursor 412 and the output cursor 421 are both advanced (act 333). Theresulting sort state 400C is illustrated in FIG. 4C.

In FIG. 4C, the integer 5 pointed to by the input cursor 411 is equal toor less than the integer 7 pointed to by the input cursor 412 (“Yes” indecision block 311). Accordingly, the corresponding element at theoutput cursor 421 is populated with the value 5 pointed to by the inputcursor 411 (act 321). There are more elements within the first sortedlist (“Yes” in decision block 322), and thus the first input cursor 411and the output cursor 421 are both advanced (act 333). The resultingsort state 400D is illustrated in FIG. 4D.

In FIG. 4D, the integer 8 pointed to by the input cursor 411 is notequal to or less than the integer 7 pointed to by the input cursor 412(“No” in decision block 311). Accordingly, the corresponding element atthe output cursor 421 is populated with the value 7 pointed to by theinput cursor 412 (act 331). There are not more elements within thesecond sorted list (“No” in decision block 332). Accordingly, the lastinteger value 8 from the first input sorted list is populated into thefinal value of the next intermediary merged sorted list (act 312), thuscompleting the first sort phase (act 314). The resulting sort state 400Eis illustrated in FIG. 4E. The position of the input cursors and theoutput cursors are not shown in FIG. 4E, as they have completed theirfunction for this first sort phase. The method would end here if therewere only two input sorted lists. Although the first input sort list Band the second input sort list C are still included in the first array401, they will not affect subsequent sort operations as they will besimply written over during subsequent sort phases. Accordingly,processing need not be wasted deleting the first input sort list B andthe second input sort list C from the first array 401.

The second sort phase may then proceed comparing again the particularexample to FIG. 3. Again, a first input cursor is established (act 301).Since this is a subsequent sort phase, the first input cursor isestablished at the first element of the prior intermediary merged sortedlist that resulted from the prior sort phase. For instance, FIG. 5Aillustrates a sorting state 500A at the beginning of the first phase ofsorting in which there is a first input cursor 511 positioned at thefirst element of the first intermediary merged sorted list.

A second input cursor is established (act 302) at the first element inthe next sorted list in the first array that has not yet been processed.In the case of the second phase, this would be the third input sortedlist in the contiguous sorted lists. In the case of FIG. 5A, in whichthe sequence includes sorted lists B, C and A contiguously positioned inthat order, the cursor 512 is positioned at the first element of theinput sorted list A.

An output cursor is established (act 303) at the beginning of theopposite array as that which contains the prior intermediary mergedsorted list (if the sort phase is after the first sort phase). Forinstance, in FIG. 5A, since the first intermediary merged sorted list isin the second array 402, the output cursor 521 is placed at thebeginning of the first array 401.

The method 300 then involves an act of generating a next intermediarymerged sorted list (act 310) by sequentially assigning values to theelements of the next intermediary sorted list. Accordingly, the contentof act 310 may be performed for each element of the next (i.e., thesecond) intermediary sorted list. This will be demonstrated referring tothe specific example with reference to FIGS. 5A through 5J.

The value of the element pointed to by the first input cursor iscompared with the value at the element pointed to by the second inputcursor (decision block 311). For instance, in FIG. 5A, the integer 2pointed to by the input cursor 511 is not equal to or less than theinteger 1 pointed to by the input cursor 512 (“No” in decision block311). Accordingly, the corresponding element of the second intermediarymerged sorted list (i.e., the element pointed to by the output cursor521) is populated with the value 1 pointed to by the input cursor 512(act 331). There are more elements within the third sorted list (“Yes”in decision block 332), and thus the second input cursor 512 and theoutput cursor 521 are both advanced (act 333). The resulting sortingstate 500B is illustrated in FIG. 5B.

In FIG. 5B, the integer 2 pointed to by the input cursor 511 is equal toor less than the integer 2 pointed to by the input cursor 512 (“Yes” indecision block 311). Accordingly, the corresponding element at theoutput cursor 521 is populated with the value 2 pointed to by the inputcursor 511 (act 321). There are more elements within the firstintermediary merged sorted list (“Yes” in decision block 322), and thusthe first input cursor 511 and the output cursor 521 are both advanced(act 323). The resulting sort state 500C is illustrated in FIG. 5C.

In FIG. 5C, the integer 4 pointed to by the input cursor 511 is notequal to or less than the integer 2 pointed to by the input cursor 512(“No” in decision block 311). Accordingly, the corresponding element atthe output cursor 521 is populated with the value 2 pointed to by theinput cursor 512 (act 331). There are more elements within the thirdsorted list (“Yes” in decision block 332), and thus the second inputcursor 512 and the output cursor 521 are both advanced (act 333). Theresulting sort state 500D is illustrated in FIG. 5D.

In FIG. 5D, the integer 4 pointed to by the input cursor 511 is notequal to or less than the integer 3 pointed to by the input cursor 512(“No” in decision block 311). Accordingly, the corresponding element atthe output cursor 521 is populated with the value 3 pointed to by theinput cursor 512 (act 331). There are more elements within the thirdsorted list (“Yes” in decision block 332), and thus the second inputcursor 512 and the output cursor 521 are both advanced (act 333). Theresulting sort state 500E is illustrated in FIG. 5E.

In FIG. 5E, the integer 4 pointed to by the input cursor 511 is equal toor less than the integer 4 pointed to by the input cursor 512 (“Yes” indecision block 311). Accordingly, the corresponding element at theoutput cursor 521 is populated with the value 4 pointed to by the inputcursor 511 (act 321). There are more elements within the firstintermediary merged sorted list (“Yes” in decision block 322), and thusthe first input cursor 511 and the output cursor 521 are both advanced(act 323). The resulting sort state 500F is illustrated in FIG. 5F.

In FIG. 5F, the integer 5 pointed to by the input cursor 511 is notequal to or less than the integer 4 pointed to by the input cursor 512(“No” in decision block 311). Accordingly, the corresponding element atthe output cursor 521 is populated with the value 4 pointed to by theinput cursor 512 (act 331). There are more elements within the thirdsorted list (“Yes” in decision block 332), and thus the second inputcursor 512 and the output cursor 521 are both advanced (act 333). Theresulting sort state 500G is illustrated in FIG. 5G.

In FIG. 5G, the integer 5 pointed to by the input cursor 511 is equal toor less than the integer 9 pointed to by the input cursor 512 (“Yes” indecision block 311). Accordingly, the corresponding element at theoutput cursor 521 is populated with the value 5 pointed to by the inputcursor 511 (act 321). There are more elements within the firstintermediary merged sorted list (“Yes” in decision block 322), and thusthe first input cursor 511 and the output cursor 521 are both advanced(act 323). The resulting sort state 500H is illustrated in FIG. 5H.

In FIG. 5H, the integer 7 pointed to by the input cursor 511 is equal toor less than the integer 9 pointed to by the input cursor 512 (“Yes” indecision block 311). Accordingly, the corresponding element at theoutput cursor 521 is populated with the value 7 pointed to by the inputcursor 511 (act 321). There are more elements within the firstintermediary merged sorted list (“Yes” in decision block 322), and thusthe first input cursor 511 and the output cursor 521 are both advanced(act 323). The resulting sort state 500I is illustrated in FIG. 5I.

In FIG. 5I, the integer 8 pointed to by the input cursor 511 is equal toor less than the integer 9 pointed to by the input cursor 512 (“Yes” indecision block 311). Accordingly, the corresponding element at theoutput cursor 521 is populated with the value 8 pointed to by the inputcursor 511 (act 321). There are not more elements within the firstintermediary merged sorted list (“No” in decision block 322).Accordingly, the last integer value 9 from the third input sorted listis populated into the final value of the second intermediary mergedsorted list (act 312), thus completing the second sort phase (act 314).The resulting sort state 500J is illustrated in FIG. 5J, with the secondintermediary merged sorted list (and the final merged list if there wereonly the three input sorted list) is included within the first array.The position of the input cursors and the output cursors are not shownin FIG. 5J, as they have completed their function for this sort phase.Although the first intermediary merged sorted list is still included inthe second array 402, these values will not affect subsequent sortoperations (if there are subsequent sort operations due to a fourth ormore input sorted list) as they will be simply written over duringsubsequent sort phases. Accordingly, processing is not wasted deletingthe first intermediary merged sorted list from the second array 402.

Method 300 may be repeated for more sorted input lists if there are moreinput sorted list. Each sorted input list results in an additional sortphase. For instance, in the case of there being 3 input sorted lists,there were two sort phases and one intermediary merged sorted list, andone final merged sorted list. More generally speaking, if there are Ninput sorted lists (where N is an integer greater than one), then therewill be N−1 sort phases, and N−2 intermediary merged sorted lists. Thelocation of the intermediary merged sorted list bounces back and forthfrom one array to the next from one sort phase to the next.

Accordingly, both the prior art priority queue method and the methodusing two pairs of arrays (hereinafter, the “array pair method”) havebeen described. It will be apparent from the length of space needed todescribe both methods, that there is more descriptive and intuitivecomplexity associated with the array pair method.

This might lead one to conclude that the array pair method is much lessefficient than the priority queue method. While this may be the case formental calculations, this is not the case when implemented using modernprocessors. For instance, the vast majority of read and write operationsassociated with the array pair method are performed sequentially.Furthermore, there are only two arrays being operated upon, making thismechanism efficient for modern processors. Furthermore, parallelisms maybe exploited using the array pair method as mentioned above.

FIG. 6 illustrates a flowchart of a method 600 for accessing inputsorted lists. The method 600 represents an example of the act 201 ofFIG. 2. The method 600 includes an act of accessing a plurality ofelements (act 601). Such elements may be unsorted. For instance,consider the following example 10 element sequence:

Unsorted Sequence: 5, 2, 1, 4, 2, 3, 8, 7, 7, 6

The multiple elements are then used to formulate multiple input sortedlists (act 610). The contents of act 610 are performed one element at atime proceeding through the elements accessed in act 601. For eachelement, it is determined whether or not there are any sorted lists thathave a tail member that has a higher priority in a sorting priority thanthe corresponding element (decision block 611). If there are not anysorted lists that have a tail member than has a higher priority in thesorting priority than the corresponding element (“No” in decision block611), a new sorted list is created (act 612) and the correspondingelement as a head element of the new sorted list (act 613). Since atthis point, the just added element is the only member of the sortedlist, the added element also happens to be the tail element of the newsorted list.

If there are one or more input sorted lists that have a tail member thathas a higher priority in the sorting priority than the correspondingelement (“Yes” in decision block 611), the corresponding element isadded to one of the one or more sorted lists that do have a tail memberof a higher sorting priority than the corresponding element. In oneembodiment, the method selects whichever of the sorted lists that has atail member that has a lowest priority in the sorting priority, whilestill being a higher priority than the corresponding element (act 614).The corresponding element is then added as a new tail member to theselected sorted list (act 615).

The act 610 will now be described with respect to the example sequenceof unsorted element, listed again as follows:

Unsorted Sequence: 5, 2, 1, 4, 2, 3, 8, 7, 7, 6

In this example, the sorting priority will be such that any subsequentelement that has a value that is equal to or greater than a previouselement will be deemed to how a lower priority than the previouselement. Upon encountering the element 5, there are not yet any sortedlists, and thus there inherently are not any sorted lists that have atail member of higher priority than this element (“No” in decision block611). Thus, a new sorted list is created (act 612) (which will be called“Sorted List I”), and the element 5 is added as the head member of thatnew sorted list (act 613). The corresponding sorted list formation statewould then appear as follows:

Unsorted Sequence: 2, 1, 4, 2, 3, 8, 7, 7, 6

Sorted List I: 5

There are more elements in the unsorted sequence to assign to a sortedlist (“Yes” in decision block 616), and thus the next element in theunsorted sequence (i.e., element 2) is evaluated. There are not anysorted lists that have a tail member that has a higher priority in thesorting priority than element 2 (“No” in decision block 612), and thus anew sorted list is created (act 612) (which will be called “Sorted ListII”), and the element 2 is added as the head member of that new sortedlist. The corresponding sorted list formation state would then appear asfollows:

Unsorted Sequence: 1, 4, 2, 3, 8, 7, 7, 6

Sorted List I: 5

Sorted List II: 2

There are more elements in the unsorted sequence to assign to a sortedlist (“Yes” in decision block 616), and thus the next element in theunsorted sequence (i.e., element 1) is evaluated. There are not anysorted lists that have a tail member that has a higher priority in thesorting priority than element 1 (“No” in decision block 612), and thus anew sorted list is created (act 612) (which will be called “Sorted ListIII”), and the element 1 is added as the head member of that new sortedlist. The corresponding sorted list formation state would then appear asfollows:

Unsorted Sequence: 4, 2, 3, 8, 7, 7, 6

Sorted List I: 5

Sorted List II: 2

Sorted List III: 1

There are more elements in the unsorted sequence to assign to a sortedlist (“Yes” in decision block 616), and thus the next element in theunsorted sequence (i.e., element 4) is evaluated. There are two sortedlists that have a tail member that have a higher priority in the sortingpriority than element 4 (“Yes” in decision block 612) (namely, SortedLists II and III). Thus, the sorted list that has the lowest prioritytail member of Sorted Lists II and III is selected (which would beSorted List II) (act 614), and the element 4 is added as the new tailmember for Sorted List II (act 615). The corresponding sorted listformation state would then appear as follows:

Unsorted Sequence: 2, 3, 8, 7, 7, 6

Sorted List I: 5

Sorted List II: 2, 4

Sorted List III: 1

There are more elements in the unsorted sequence to assign to a sortedlist (“Yes” in decision block 616), and thus the next element in theunsorted sequence (i.e., element 2) is evaluated. There is only onesorted list that has a tail member that has a higher priority in thesorting priority than element 2 (“Yes” in decision block 612) (namely,Sorted List III). Thus, the Sorted List III is selected (act 614), andthe element 2 is added to the Sorted List III (act 615). Thecorresponding sorted list formation state would then appear as follows:

Unsorted Sequence: 3, 8, 7, 7, 6

Sorted List I: 5

Sorted List II: 2, 4

Sorted List III: 1, 2

There are more elements in the unsorted sequence to assign to a sortedlist (“Yes” in decision block 616), and thus the next element in theunsorted sequence (i.e., element 3) is evaluated. There is only onesorted list that has a tail member that has a higher priority in thesorting priority than element 3 (“Yes” in decision block 612) (namely,Sorted List III). Thus, the Sorted List III is selected (act 614), andthe element 3 is added to the Sorted List III (act 615). Thecorresponding sorted list formation state would then appear as follows:

Unsorted Sequence: 8, 7, 7, 6

Sorted List I: 5

Sorted List II: 2, 4

Sorted List III: 1, 2, 3

There are more elements in the unsorted sequence to assign to a sortedlist (“Yes” in decision block 616), and thus the next element in theunsorted sequence (i.e., element 8) is evaluated. All sorted lists havea tail member that has a higher priority in the sorting priority thanelement 8 (“Yes” in decision block 612). Thus, the sorted list that hasthe lowest priority tail member of the sorted list (which would beSorted List I) is selected (act 614), and the element 8 is added as thenew tail member for Sorted List I (act 615). The corresponding sortedlist formation state would then appear as follows:

Unsorted Sequence: 7, 7, 6

Sorted List I: 5, 8

Sorted List II: 2, 4

Sorted List III: 1, 2, 3

There are more elements in the unsorted sequence to assign to a sortedlist (“Yes” in decision block 616), and thus the next element in theunsorted sequence (i.e., element 7) is evaluated. There are two sortedlists that have a tail member that has a higher priority in the sortingpriority than element 7 (“Yes” in decision block 612) (namely, SortedLists II and III). Thus, the sorted list that has the lowest prioritytail member of Sorted Lists II and III is selected (which would beSorted List II) (act 614), and the element 7 is added as the new tailmember for Sorted List II (act 615). The corresponding sorted listformation state would then appear as follows:

Unsorted Sequence: 7, 6

Sorted List I: 5, 8

Sorted List II: 2, 4, 7

Sorted List III: 1, 2, 3

There are more elements in the unsorted sequence to assign to a sortedlist (“Yes” in decision block 616), and thus the next element in theunsorted sequence (i.e., element 7) is evaluated. There are two sortedlists that have a tail member that has a higher priority in the sortingpriority than element 7 (“Yes” in decision block 612) (namely, SortedLists II and III). Thus, the sorted list that has the lowest prioritytail member of Sorted Lists II and III is selected (which would beSorted List II) (act 614), and the element 7 is added as the new tailmember for Sorted List II (act 615). The corresponding sorted listformation state would then appear as follows:

Unsorted Sequence: 6

Sorted List I: 5, 8

Sorted List II: 2, 4, 7, 7

Sorted List III: 1, 2, 3

There is one more element in the unsorted sequence to assign to a sortedlist (“Yes” in decision block 616), and thus the last element in theunsorted sequence (i.e., element 6) is evaluated. There is only onesorted list that has a tail member that has a higher priority in thesorting priority than element 3 (“Yes” in decision block 612) (namely,Sorted List III). Thus, the Sorted List III is selected (act 614), andthe element 6 is added to the Sorted List III (act 615). Thecorresponding sorted list formation state would then appear as follows:

Unsorted Sequence: *

Sorted List I: 5, 8

Sorted List II: 2, 4, 7, 7

Sorted List III: 1, 2, 3, 6

Since the unsorted sequence is now empty (“No” in decision block 616),the method 600 ends. Note that at each point, the sorted lists areordered in sequence of lower to higher priority of each tail member inthe sorting priority. Acts 611 through 616 have actually been previouslypublicly disclosed as part of the “Patience Method”.

However, as an improvement to the formation of the input sorted list,the principles described herein may mark the last sorted list to which aprior element was added from the unsorted sequence. The comparison ofthe next element from the unsorted sequence is then begun by comparingwith the tail member of that marked sorted list. If the new element hasa higher sorting priority than the tail member of the marked sortedlist, a comparison of the element from the unsorted sequence isperformed against a previous list (if there exists a previous list). Ifthe new element has a higher sorting priority than the tail member ofthat previous list (or if there is not a previous list, then the newelement is added as a new tail member of that marked list. Otherwise,the compassion operation moves to the next sorted list in the sequencein a direction of decreasing priority in the sorting priority (e.g.,upward from Sorted List III to Sorted List II, or upwards from SortedList II to Sorted List I in the example above) and the new element iscompared against the tail member in that next lower priority tail membersorted list. If the new element has a lower sorting priority than thetail member of the marked sorted list, the comparison moves to the nextsorted list in the sequence in a direction of increasing priority in thesorting priority (e.g., downward from Sorted List Ito Sorted List II, ordownwards from Sorted List II to Sorted List III in the example above)and the new element is compared against the tail member in that nexthigher priority tail member sorted list.

FIG. 7 illustrates a flowchart of a more generalized method 700 forprocessing elements to form sorted lists. The method 700 includes an actof forming multiple input sorted lists (act 701) followed by an act ofmerging the input sorted lists into a merged sorted list (act 702). Anexample of the act 701 has been described above with respect to FIG. 6,but the act 701 is not limited to that method. An example of the act 702has been described with respect to FIGS. 2 and 3, although the act 702is not limited to that method.

The principles described herein may operate with a stream of elements.In this case, perhaps there is not enough memory to hold all of theelements in the stream. Accordingly, perhaps only a portion of theelements are subjected to the method 700 to formulate a first mergedsorted list. For instance, in one of the above examples, the unsortedsequence of elements include 10 elements as follows:

Unsorted Sequence: 5, 2, 1, 4, 2, 3, 8, 7, 7, 6

However, suppose that there was only room to process the first 8elements of the unsorted sequence as follows:

Unsorted Sequence (Part I): 5, 2, 1, 4, 2, 3, 8, 7

Applying the method 600 (an example of act 701), the processing wouldproceed the same as the first eight elements as described above in orderto result in the following sorted input list.

Sorted List I: 5, 8

Sorted List II: 2, 4, 7

Sorted List III: 1, 2, 3

Act 702 may then be performed to formulate a merged sorting list asfollows:

Merged Sorted List: 1, 2, 2, 3, 4, 5, 7, 8

The higher prioritized values of the merged sorted list are thenpersisted in storage. For instance, suppose that the highest priorityhalf (e.g., those of values of 3 or less) of the merged sorted list arepreserved in persistent storage. The corresponding persisted values arethen removed from the input sorted list. This would result in thefollowing relevant state:

Sorted List I (in Memory): 5, 8

Sorted List II (in Memory): 4, 7

Sorted List III (in Memory): * (empty)

Persisted Elements: 1, 2, 2, 3

The additional elements from the unsorted sequence (namely, 7 and 6) arethen processed through act 701. For instance, using method 600, the newelement 7 would be assigned to the Sorted List II, resulting in thefollowing state:

Sorted List I (in Memory): 5, 8

Sorted List II (in Memory): 4, 7, 7

Sorted List III (in Memory): * (empty)

Persisted Elements: 1, 2, 2, 3

The last element 6 of the unsorted sequence would then be assigned tothe

Sorted List III resulting in the following state:

Sorted List I (in Memory): 5, 8

Sorted List II (in Memory): 4, 7, 7

Sorted List III (in Memory): 6

Persisted Elements: 1, 2, 2, 3

Act 702 is then again applied to formulate the following state:

Sorted List I (in Memory): 5, 8

Sorted List II (in Memory): 4, 7, 7

Sorted List III (in Memory): 6

Merged Sorted List: 4, 5, 6, 7, 7, 8

Persisted Elements: 1, 2, 2, 3

The remainder of the merged sorted list may then be appended to thepersisted elements to form the following persisted and sorted elements:

Persisted Elements: 1, 2, 2, 3, 4, 5, 6, 7, 7, 8

In a second example of streamed elements, there might be a stream thatincludes multiple elements, but also includes a notification at somepoint that additional elements that are beyond that point only includevalues that have lower prioritized sort priority than any of the valuesin the plurality of sorted lists. Thus, the method 700 may be performedto sort all of the elements up to the point of that notification. Then,the method 700 may separately be performed for all elements received inthe stream after that point until the stream ends or until a similarnotification is encountered again.

Accordingly, the principles described herein provide an effectivemechanism to merge multiple input sorted lists into a single mergedsorted list, and for formulating the input sorted lists, even of theunsorted sequence is received over a stream, or is too large to fit inmemory at the same time.

The present invention may be embodied in other specific forms withoutdeparting from its spirit or essential characteristics. The describedembodiments are to be considered in all respects only as illustrativeand not restrictive. The scope of the invention is, therefore, indicatedby the appended claims rather than by the foregoing description. Allchanges which come within the meaning and range of equivalency of theclaims are to be embraced within their scope.

What is claimed is:
 1. A method for formulating a merged sorted list,the method comprising: an act of accessing a plurality of input sortedlists; an act of contiguously populating a first array with theplurality of input sorted lists; an act of using the first array and asecond array to merge the plurality of input sorted lists into a mergedsorted list, wherein the merging occurs by merging the first and secondsorted lists.
 2. The method in accordance with claim 1, wherein the actof accessing the plurality of input sorted lists comprises: an act ofaccessing a plurality of elements; and an act of using the plurality ofelements to formulate the plurality of input sorted lists.
 3. The methodin accordance with claim 2, wherein the act of using the plurality ofelements to formulate the plurality of input sorted lists comprises thefollowing proceeding one element at a time through the plurality ofelements: an act of determining whether or not there are any inputsorted lists that have a tail member that has a higher priority in asorting priority than the corresponding element, if there are not anyinput sorted lists that have a tail member than has a higher priority inthe sorting priority than the corresponding element, an act of creatinga new input sorted list and an act of adding the corresponding elementas a head element of the new input sorted list, the correspondingelement also being a tail element of the new input sorted list since thecorresponding element is the only element of the new input sorted list;if there are one or more input sorted lists that have a tail member thathas a higher priority in the sorting priority than the correspondingelement, an act of adding the corresponding element to one of the one ormore input sorted lists such that the corresponding element becomes anew tail member of the input sorted list to which the correspondingelement is added.
 4. The method in accordance with claim 3, wherein ifthere are multiple input sorted lists that have a tail member that has ahigher priority in the sorting priority than the corresponding element,an act of selecting whichever of the multiple sorted lists have a tailmember that has a lowest priority in the sorting priority as the inputsorted list to which to add the corresponding element as a new tailmember.
 5. The method in accordance with claim 4, wherein the inputsorted lists are ordered in sequence of lower to higher priority of eachtail member in the sorting priority.
 6. The method in accordance withclaim 5, wherein for a given element of the plurality of elements, theact of determining whether or not there are any input sorted lists thathave a tail member that has a higher priority in a sorting priority thanthe corresponding element, and the act of selecting whichever of themultiple input sorted lists has a tail member that has a lowest priorityin the sorting priority as the sorted list to which to add thecorresponding element as a new tail member, comprises the following: anact of marking a last input sorted list to which a prior element of theplurality of elements was added; an act of beginning a comparison of thegiven element with the tail member of the marked sorted list.
 7. Themethod in accordance with claim 1, wherein the merging occurs in aplurality of phases, wherein the merging of the first and second sortedlists occurs in a first phase of the plurality of phases and results ina first intermediary merged list, the plurality of phases furthercomprising: a subsequent plurality of phases each merging a priorintermediary merged list resulting from a prior phase of the pluralityof phases with a next input sorted list of the plurality of input sortedlists to generate a next intermediary merged list, or a merged sortedlist if there or no further input sorted lists after the next inputsorted list in the plurality of input sorted lists, wherein a locationof the intermediary merged list alternates between the first array andthe second array from one phase of the plurality of phases to the nextphase of the plurality of phases.
 8. A computer program productcomprising one or more computer-readable storage media having thereoncomputer-executable instructions that are structured such that, whenexecuted by one or more processors of the computing system, cause thecomputing system to perform a method comprising an act of merging aplurality of sorted lists to form a merged sorted list, the act mergingthe plurality of sorted lists comprising: an act representing a firstsorted list and a second sorted list contiguously in a first pluralityof elements in a first array in memory an act of establishing a firstinput cursor at the first element in the first sorted list in the firstarray; an act of establishing a second input cursor at the first elementin the second sorted list in the first array; an act of formulating asecond array in memory, the second array including at least a portionthat includes a second plurality of elements equal in number to thefirst plurality of elements; an act of sequentially assigning values tothe elements of the second plurality of elements to thereby formulated afirst merged sorted list of the first and second sorted lists, the actof sequentially assigning comprising performing the following for eachof the first element through a subsequent element in the secondaryplurality of elements: an act of comparing a value at an element pointedto by the first input cursor with a value at the element pointed to bythe second input cursor; if the value at the element pointed to by thefirst input cursor satisfies a sorting priority with respect to thevalue at the element pointed to by the second input cursor; an act ofpopulating the corresponding element of the second plurality of elementswith the value at the element pointed to by the first input cursor; andan act of moving the first input cursor to a next element in the firstsorted list of the first plurality of elements if there are any furtherelements in the first sorted list, and if there are not any furtherelements in the first sorted list, the corresponding element of thesecond plurality of elements is the subsequent element of the secondplurality of elements, and thus the method further includes an act offurther populating a remainder of the second plurality of elements withany remaining unprocessed elements of the second sorted list from anelement pointed to by the second input cursor; and if the value at theelement pointed to by the first input cursor does not satisfy a sortingpriority with respect to the value at the element pointed to by thesecond input cursor; an act of populating the corresponding element ofthe second plurality of elements with the value at the element pointedto by the second input cursor; and an act of moving the second inputcursor to a next element in the second sorted list of the firstplurality of elements if there are any further elements in the secondsorted list, and if there are not any further elements in the secondsorted list, the corresponding element of the second plurality ofelements is the subsequent element of the second plurality of elements,and thus the method further includes an act of further populating aremainder of the second plurality of elements with any remainingunprocessed elements of the first sorted list from an element pointed toby the first input cursor.
 9. The computer program product in accordancewith claim 8, wherein the first array includes a third sorted listarranged contiguously with the first plurality of elements in the firstarray to form a first superset plurality of elements in the first array,the method further comprising an act of merging the first merged sortedlist with the third sorted list comprising: an act of establishing thefirst input cursor at the first element in the first merged sorted listin the second plurality of elements in the second array; an act ofestablishing a second input cursor at the first element in the thirdsorted list in the first array; an act of sequentially assigning valuesto the elements of the first superset plurality of elements in the firstarray to thereby formulate a second merged sorted list of the first,second and third sorted lists, the act of sequentially assigning valuesto the elements of the first superset plurality of elements comprisingperforming the following for each of the first element through asubsequent element in the first superset plurality of elements: an actof comparing a value at an element pointed to by the first input cursorwith a value at the element pointed to by the second input cursor; ifthe value at the element pointed to by the first input cursor satisfiesthe sorting priority with respect to the value at the element pointed toby the second input cursor; an act of populating the correspondingelement of the first superset plurality of elements with the value atthe element pointed to by the first input cursor; and an act of movingthe first input cursor to a next element in the first merged sorted listof the first plurality of elements if there are any further elements inthe first merged sorted list, and if there are not any further elementsin the first merged sorted list, the corresponding element of the firstsuperset plurality of elements is the subsequent element of the firstsuperset plurality of elements, and thus the method further includes anact of further populating a remainder of the first superset plurality ofelements with any remaining unprocessed elements of the third sortedlist from an element pointed to by the second input cursor; and if thevalue at the element pointed to by the first input cursor does notsatisfy the sorting priority with respect to the value at the elementpointed to by the second input cursor; an act of populating thecorresponding element of the first superset plurality of elements withthe value at the element pointed to by the second input cursor; and anact of moving the second input cursor to a next element in the thirdsorted list of the first array if there are any further elements in thethird sorted list, and if there are not any further elements in thethird sorted list, the corresponding element of the first supersetplurality of elements is the subsequent element of the first supersetplurality of elements, and thus the method further includes an act offurther populating a remainder of the first superset plurality ofelements with any remaining unprocessed elements of the first mergedsorted list from an element pointed to by the first input cursor. 10.The computer program product in accordance with claim 8, wherein theplurality of sorted lists is a first plurality of sorted lists, and themerged sorted list is a first merged sorted list, the method furthercomprising: an act of persisting in sort order those higher prioritizedvalues of the merged sorted list that have a more prioritized sortpriority; an act of removing the persisted values from the firstplurality of sorted lists; an act of accessing at least one additionalelement; an act of formulating a second plurality of sorted lists usinga combination of the at least one additional element and any remainingsorted lists of the first plurality of the sorted lists that remainafter the act of removing; and an act of formulating a second mergedsorted list using the second plurality of sorted lists.
 11. The computerprogram product in accordance with claim 8, wherein the act of mergingthe plurality of sorted lists to form the merged sorted list isperformed in response to an act of detecting a notification thatadditional sorted lists in a stream of sorted lists that are beyond theplurality of sorted lists only include values that have lowerprioritized sort priority than any of the values in the plurality ofsorted lists.
 12. The computer program product in accordance with claim11, wherein the plurality of sorted lists is a first plurality of sortedlists, and the merged sorted list is a first merged sorted list, themethod further comprising: after the act of formulating the first mergedsorted listed, an act of formulating a second merged sorted list using aplurality of elements received in the stream of sorted lists after thenotification.
 13. The computer program product in accordance with claim12, the method further comprising: an act of appending the second mergedsorted list to the end of the first merged sorted list.
 14. The computerprogram product in accordance with claim 8, wherein the plurality ofsorted lists are ordered in the first array such that a longest sortedlist of the plurality of sorted lists is last in the first array. 15.The computer program product in accordance with claim 8, wherein themethod further comprises the following prior to the act of merging theplurality of sorted lists: an act of arranging the plurality of sortedlists in order of increasing size such that any sorted list within thefirst array is equal to or smaller in number of elements than the numberof elements of any of the sorted lists that appear after the givensorted list within the first array.
 16. A method comprising an act ofmerging a plurality of sorted lists to form a merged sorted list, themethod comprising: an act of accessing a plurality of sorted listsincluding a first sorted list and a second sorted list; an actrepresenting the first sorted list and the second sorted listcontiguously in a first array in memory, the portion of the first arraythat includes the first and second sorted listing including a firstplurality of elements; an act of establishing a first input cursor atthe first element in the first sorted list in the first array; an act ofestablishing a second input cursor at the first element in the secondsorted list in the first array; an act of formulating a second array inmemory, the second array including a portion that includes a secondplurality of elements equal in number to the first plurality ofelements; an act of sequentially assigning values to at least some ofthe elements of the second plurality of elements, the act ofsequentially assigning comprising: an act of populating a first elementof the second plurality of elements, the act of populating the firstelement comprising: an act of comparing a value at an element pointed toby the first input cursor with a value at the element pointed to by thesecond input cursor; if the value at the element pointed to by the firstinput cursor satisfies a sorting priority with respect to the value atthe element pointed to by the second input cursor; an act of populatingthe first element of the second plurality of elements with the value atthe element pointed to by the first input cursor; and an act of movingthe first input cursor to a next element, if any, in the first sortedlist of the first plurality of elements; and if the value at the elementpointed to by the first input cursor does not satisfy a sorting prioritywith respect to the value at the element pointed to by the second inputcursor; an act of populating the first element of the second pluralityof elements with the value at the element pointed to by the second inputcursor; and an act of moving the second input cursor to a next element,if any, in the second sorted list of the first plurality of elements;and an act of populating a second element of the second plurality ofelements after the act of populating the first element of the secondplurality of elements, the act of populating the second elementcomprising: an act of comparing a value at an element pointed to by thefirst input cursor with a value at the element pointed to by the secondinput cursor; if the value at the element pointed to by the first inputcursor satisfies the sorting priority with respect to the value at theelement pointed to by the second input cursor; an act of populating thesecond element of the second plurality of elements with the value at theelement pointed to by the first input cursor; and if the value at theelement pointed to by the first input cursor does not satisfy thesorting priority with respect to the value at the element pointed to bythe second input cursor; an act of populating the second element of thesecond plurality of elements with the value at the element pointed to bythe second input cursor.
 17. The method in accordance with claim 16,wherein the plurality of sorted lists are ordered in order of increasingsize in the first array.
 18. The method in accordance with claim 16,wherein the act of populating the second element of the second pluralityof elements further comprises the following: if the value at the elementpointed to by the first input cursor satisfies the sorting priority withrespect to the value at the element pointed to by the second inputcursor; an act of moving the first input cursor to a next element in thefirst sorted list of the first plurality of elements; and if the valueat the element pointed to by the first input cursor does not satisfy thesorting priority with respect to the value at the element pointed to bythe second input cursor, an act of moving the second input cursor to anext element in the second sorted list of the first plurality ofelements; the method further comprising an act of populating a thirdelement of the second plurality of elements after the act of populatingthe second element of the second plurality of elements, the act ofpopulating the third element comprising: an act of comparing a value atan element pointed to by the first input cursor with a value at theelement pointed to by the second input cursor; if the value at theelement pointed to by the first input cursor satisfies the sortingpriority with respect to the value at the element pointed to by thesecond input cursor; an act of populating the third element of thesecond plurality of elements with the value at the element pointed to bythe first input cursor; and if the value at the element pointed to bythe first input cursor does not satisfy the sorting priority withrespect to the value at the element pointed to by the second inputcursor; an act of populating the third element of the second pluralityof elements with the value at the element pointed to by the second inputcursor.
 19. The method in accordance with claim 18, wherein the act ofpopulating the third element of the second plurality of elements furthercomprises the following: if the value at the element pointed to by thefirst input cursor satisfies the sorting priority with respect to thevalue at the element pointed to by the second input cursor; an act ofmoving the first input cursor to a next element in the first sorted listof the first plurality of elements; and if the value at the elementpointed to by the first input cursor does not satisfy the sortingpriority with respect to the value at the element pointed to by thesecond input cursor, an act of moving the second input cursor to a nextelement in the second sorted list of the first plurality of elements;the method further comprising an act of populating a fourth element ofthe second plurality of elements after the act of populating the thirdelement of the second plurality of elements, the act of populating thefourth element comprising: an act of comparing a value at an elementpointed to by the first input cursor with a value at the element pointedto by the second input cursor; if the value at the element pointed to bythe first input cursor satisfies the sorting priority with respect tothe value at the element pointed to by the second input cursor; an actof populating the fourth element of the second plurality of elementswith the value at the element pointed to by the first input cursor; andif the value at the element pointed to by the first input cursor doesnot satisfy the sorting priority with respect to the value at theelement pointed to by the second input cursor; an act of populating thefourth element of the second plurality of elements with the value at theelement pointed to by the second input cursor.
 20. The method inaccordance with claim 19, wherein the act of populating the fourthelement of the second plurality of elements further comprises thefollowing: if the value at the element pointed to by the first inputcursor satisfies the sorting priority with respect to the value at theelement pointed to by the second input cursor; an act of moving thefirst input cursor to a next element in the first sorted list of thefirst plurality of elements; and if the value at the element pointed toby the first input cursor does not satisfy the sorting priority withrespect to the value at the element pointed to by the second inputcursor, an act of moving the second input cursor to a next element inthe second sorted list of the first plurality of elements; the methodfurther comprising an act of populating a fifth element of the secondplurality of elements after the act of populating the fourth element ofthe second plurality of elements, the act of populating the fifthelement comprising: an act of comparing a value at an element pointed toby the first input cursor with a value at the element pointed to by thesecond input cursor; if the value at the element pointed to by the firstinput cursor satisfies the sorting priority with respect to the value atthe element pointed to by the second input cursor; an act of populatingthe fifth element of the second plurality of elements with the value atthe element pointed to by the first input cursor; and if the value atthe element pointed to by the first input cursor does not satisfy thesorting priority with respect to the value at the element pointed to bythe second input cursor; an act of populating the fifth element of thesecond plurality of elements with the value at the element pointed to bythe second input cursor.